package com.leyou.item.mapper;

import com.leyou.item.pojo.Brand;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

@Component
public interface BrandMapper extends Mapper<Brand> {

    /**
     * 新增分类id和产品id
     * @param cid
     * @param bid
     */

    @Insert("insert into tb_category_brand(category_id,brand_id) values (#{cid},#{bid})")
    void insertCategoryAndBrand(@Param("cid") Long cid,@Param("bid") Long bid);

    /**
     * 更新中间表
     * @param cid
     * @param bid
     */
    @Update("update tb_category_brand set category_id = #{cid} where brand_id = #{bid} ")
    void updateCategoryAndBrand(@Param("cid") Long cid,@Param("bid") Long bid);

    /**
     * 删除中间表
     * @param bid
     */
    @Delete("delete from tb_category_brand where brand_id = #{bid}")
    void deleteCategoryAndBrand(Long bid);

    /**
     * 根据cid查询品牌
     * @param cid
     * @return
     */
    @Select("select * from tb_brand b inner join tb_category_brand cb \n" +
            " on  b.id = cb.brand_id where cb.category_id = #{cid}")
    List<Brand> queryBrandByCid(Long cid);
}
